<?php

namespace Marketing\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Marketing\Model\Entity\Marketinglist;
use Marketing\Form\MarketinglistForm;
use Zend\Db\Adapter\Adapter;
use Marketing\Model\MarketingTable;


class MarketingController extends AbstractActionController
{
	
	protected $_MarketingTable;
	
	public function getMarketingTable() {
		if (!$this->_MarketingTable) {
			$sm = $this->getServiceLocator();
			$this->_MarketingTable = $sm->get('Marketing\Model\MarketingTable');
		}
		return $this->_MarketingTable;
	}
	
	public function indexAction()
    {
    }
    
    public function createlistAction()
    {      	
    	$form = new MarketinglistForm();
    	$form->get('submit')->setValue('Save');
    	$request = $this->getRequest();

    	if ($request->isPost()) {
    		$Marketinglist = new Marketinglist();
    		$form->setInputFilter($Marketinglist->getInputFilter());
    		$form->setData($request->getPost());
    		
    		if($form->isValid())
    		{
    			echo 'valid';
    			$Marketinglist->exchangeArray($form->getData());
    			$this->getMarketingTable()->saveMarketinglist($Marketinglist);
    		}
    		echo $Marketinglist->getName();
    		
    		$testing = $form->getData();
    		echo $testing['name'];
    	}
    	return array('form' => $form);
    }
    
    public function listAction()
    {
    	    	return new ViewModel(array(
                    'marketinglists' => $this->getMarketingTable()->fetchAll(),
                ));
    }

    public function listeditAction()
    {
    	return new ViewModel(array(
    			'marketinglists' => $this->getMarketingTable()->fetchDetail(),
    	));
    	
    }
    
    public function listdetailAction(){
    	
    }
    

    
}
